package br.com.materiais.form;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import br.com.materiais.dao.MateriaisDao;
import br.com.materiais.model.MaterialModel;

public class PesquisaMateriaisForm extends ActionForm
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 760068879568356457L;
	
	private MaterialModel pesquisar = new MaterialModel();
	
	public MaterialModel getPesquisar()
	{
		return this.pesquisar;
	}
	
    @SuppressWarnings("unchecked")
	@Override
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 
	{
		ActionErrors erros = new ActionErrors();
		
		List lista = new MateriaisDao().getListaMateriais(pesquisar);
		if(lista.isEmpty())
		{
			erros.add("registro",new ActionMessage("registro.nao.encontrado"));
		}
		return erros;
	}
}
